﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase.Tools;
using INTEX.DataBase;
namespace WPFExcelReport
{

    public class JLTVKWZData : BaseFunction
    {

        SETINTEXDB INTEXDB = new SETINTEXDB();
        ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        INTEXBL INTEXBL
        {
            get
            {
                return app.INTEXBL;
            }
        }
        INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        DataRow dwTemp;
        JLTWVKDOCData m_vkd = new JLTWVKDOCData();
        public JLTVKWZData()
            : base()
        {
            Helpers.Helper.GetDate(ref date, ref year, ref month, ref day);
        }
        public JLTVKWZData(OracleConnection _myConnection, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_myConnection, _proxy, userID)
        {
           
           
        }
    
        public DataSet BuildData(DataRow dwInput, bool byArt)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            try
            {
                string MANDANT, KRS, LFD;
                MANDANT = dwInput["VKPMANDANT"].ToString();
                KRS = dwInput["VKPAUFKRS"].ToString();
                LFD = dwInput["VKPAUFLFD"].ToString();
                dwTemp = INTEXDB.VKKOPF.NewRow();
                dwTemp["VKKMANDANT"] = dwInput["VKPMANDANT"];
                dwTemp["VKKAUFKRS"] = dwInput["VKPAUFKRS"];
                dwTemp["VKKAUFLFD"] = dwInput["VKPAUFLFD"];
                SResult = m_vkd.GetData(MANDANT,KRS,LFD);
                SReturn.Merge(SResult);
                dwTemp = INTEXDB.WBBST.NewRow();
                if (!byArt)
                {
                    dwTemp["WBBMANDANT"] = dwInput["VKPMANDANT"];
                    dwTemp["WBBAUFTYP"] = "K";
                    dwTemp["WBBWAKZ"] = "F";
                    
                    dwTemp["WBBAUFKRS"] = dwInput["VKPAUFKRS"];
                    dwTemp["WBBAUFLFD"] = dwInput["VKPAUFLFD"];
                    dwTemp["WBBAUFPOS"] = dwInput["VKPAUFPOS"];
                    SResult = INTEXDBC.QueryWBBST(dwTemp, 3);
                }
                else
                {
                    dwTemp["WBBMANDANT"] = dwInput["VKPMANDANT"];
                    dwTemp["WBBWAKZ"] = "F";
                    dwTemp["WBBART"] = dwInput["VKPART"];
                    dwTemp["WBBFARBE"] = dwInput["VKPFARBE"];
                    dwTemp["WBBLO"] = "01";
                    dwTemp["WBBLB"] =Left(dwInput["VKPAENDST"].ToString()+"         ",2);
                    SResult = INTEXDBC.QueryWBBST(dwTemp, 7);
                }
                SReturn.Merge(SResult);
                dwTemp = INTEXDB.VVTLIEF.NewRow();
                dwTemp["VVTMANDANT"] = dwInput["VKPMANDANT"];
                dwTemp["VVTAUFTYP"] = "K";
                dwTemp["VVTAUFKRS"] = dwInput["VKPAUFKRS"];
                dwTemp["VVTAUFLFD"] = dwInput["VKPAUFLFD"];
                SResult = INTEXDBC.QueryVVTLIEF(dwTemp, 2);
                SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
    }
}